/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package flightlifter;

import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL20;



public class Particle{

    PVector pos;
    PVector vel;
    float rx,drx;
    float ry,dry;
    float rz,drz;

    int life = 0;
    int maxLife = 0;

    float scale = 1;
    float dScale = .1f;

    float shade;

    public Particle(PVector pos, PVector vel, float rx, float drx,
            float ry, float dry,float rz, float drz, int maxLife){

        this.pos = pos;
        this.vel = vel;
        this.rz = rz;
        this.drz = drz;
        this.rx = rx;
        this.drx = drx;
        this.ry = ry;
        this.dry = dry;

        this.maxLife = maxLife;
        shade = (float)Math.random()/3.f;
    }

    public void physics(){
        life++;
        pos.add(vel);
        scale += dScale;
        rx += drx;
        rz += drz;
        ry += dry;

        vel.mult(.95f);
        drx *= .95f;
        dry *= .95f;
        drz *= .95f;

        if (pos.y < 0) {
            pos.y = -pos.y;
            vel.y = -vel.y;
        }

    }

    public void render(){

        GL11.glPushMatrix();

 
        GL11.glTranslatef(pos.x, pos.y, pos.z);

        GL11.glRotatef(rx, 1.f, 0, 0);
        GL11.glRotatef(ry, 0, 1.f, 0);
        GL11.glRotatef(rz, 0, 0, 1.f);
        GL11.glScalef(scale, scale, scale);


        float opacity = life/(float)maxLife;

        opacity *= opacity;


        GL11.glColor4f(shade,shade,shade,.75f-opacity);
        

        GL11.glBegin(GL11.GL_QUADS);
        
        GL11.glVertex3f(-1,-1,0);
        GL11.glVertex3f(1,-1,0);
        GL11.glVertex3f(1,1,0);
        GL11.glVertex3f(-1,1,0);
        GL11.glEnd();

        GL11.glPopMatrix();

    }

}